CROSS_COMPILE = aarch64-linux-gnu-
CC	=	$(CROSS_COMPILE)gcc
#CXX	=	$(CROSS_COMPILE)g++ -g
CXX	=	$(CROSS_COMPILE)g++
AR	=	$(CROSS_COMPILE)ar
LD	=	$(CROSS_COMPILE)ld
OBJDUMP =	$(CROSS_COMPILE)objdump
STRIP	=	$(CROSS_COMPILE)strip
RM	=	rm	

CFLAGS := -Wall 
#CFLAGS += -g
CFLAGS_CPP := -Wall
#CFLAGS_CPP += -g

LDFLAGS = -lpthread -lm -ldl

SRCS    :=  $(wildcard *.c)
OBJS    :=  $(SRCS:%.c=%.o)

SRCS_CPP    :=  $(wildcard *.cpp)
OBJS_CPP    :=  $(SRCS_CPP:%.cpp=%.o)

ARM = arm
INTERL = intel
PWD = $(pwd)

TARGET := $(OBJS:%.o=%) 
TARGET_CPP := $(OBJS_CPP:%.o=%)

.PHONY : clean all

all: $(TARGET) $(TARGET_CPP)
$(TARGET):%:%.o
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
	mkdir -p $(ARM)
	####(CC) $(CFLAGS) $@.c  -S -o $(ARM)/$@.asm		# .c --> .s
	#$(OBJDUMP) -S $^ > $(ARM)/$^.s				# .o
	$(OBJDUMP) -S $@ > $(ARM)/$@.s				# exe file
	$(STRIP) $@
	$(OBJDUMP) -S $@ > $(ARM)/$@$s-strip.s	# exe file	# strip exe file

$(TARGET_CPP):%:%.o
	$(CXX) $(CFLAGS_CPP) -o $@ $^ $(LDFLAGS)
	mkdir -p $(ARM)
	####(CXX) $(CFLAGS_CPP) $@.c  -S -o $(ARM)/$@.asm	# .c --> .s
	#$(OBJDUMP) -S $^ > $(ARM)/$^.s				# .o
	$(OBJDUMP) -S $@ > $(ARM)/$@.s				# exe file
	$(STRIP) $@
	$(OBJDUMP) -S $@ > $(ARM)/$@$s-strip.s	# exe file	# strip exe file

clean:
	@rm -f $(TARGET)
	@rm -f $(TARGET_CPP)
	@rm -f $(OBJS)
	@rm -f $(OBJS_CPP)
	@rm -rf $(ARM)
	@rm -rf $(INTERL)
	@find . -name "*~" | xargs rm > /dev/null 2>&1  &

